/*
 * Copyright (c) 2018. J4dream Created.
 */

package com.j4dream.property.javabasic.thread;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.mail.javamail.JavaMailSender;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class ThreadFactoryDemo {

    private Executor executor;

    public ThreadFactory getThreadFactory() {
        ThreadFactory threadFactory = new ThreadFactoryBuilder()
                .setNameFormat("my-thread-test-%d")
                .build();
        executor = Executors.newCachedThreadPool();
        return threadFactory;
    }


    public static void main(String[] args) {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("my-thread-test-%d").build();
        Executor executor = Executors.newCachedThreadPool(threadFactory);
        executor.execute(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName());
                System.out.println(i);
            }
        });
        executor.execute(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName());
                System.out.println(i);
            }
        });
    }

}
